package com.ruoyi.web.controller.product;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.DisableMedicine;
import com.ruoyi.system.service.IDisableMedicineService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 禁用农药Controller
 * 
 * @author ruoyi
 * @date 2025-01-23
 */
@RestController
@RequestMapping("/system/medicine")
public class DisableMedicineController extends BaseController
{
    @Autowired
    private IDisableMedicineService disableMedicineService;

    /**
     * 查询禁用农药列表
     */
    @PreAuthorize("@ss.hasPermi('system:medicine:list')")
    @GetMapping("/list")
    public TableDataInfo list(DisableMedicine disableMedicine)
    {
        startPage();
        List<DisableMedicine> list = disableMedicineService.selectDisableMedicineList(disableMedicine);
        return getDataTable(list);
    }

    /**
     * 导出禁用农药列表
     */
    @PreAuthorize("@ss.hasPermi('system:medicine:export')")
    @Log(title = "禁用农药", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DisableMedicine disableMedicine)
    {
        List<DisableMedicine> list = disableMedicineService.selectDisableMedicineList(disableMedicine);
        ExcelUtil<DisableMedicine> util = new ExcelUtil<DisableMedicine>(DisableMedicine.class);
        util.exportExcel(response, list, "禁用农药数据");
    }

    /**
     * 获取禁用农药详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:medicine:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(disableMedicineService.selectDisableMedicineById(id));
    }

    /**
     * 新增禁用农药
     */
    @PreAuthorize("@ss.hasPermi('system:medicine:add')")
    @Log(title = "禁用农药", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DisableMedicine disableMedicine)
    {
        return toAjax(disableMedicineService.insertDisableMedicine(disableMedicine));
    }

    /**
     * 修改禁用农药
     */
    @PreAuthorize("@ss.hasPermi('system:medicine:edit')")
    @Log(title = "禁用农药", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DisableMedicine disableMedicine)
    {
        return toAjax(disableMedicineService.updateDisableMedicine(disableMedicine));
    }

    /**
     * 删除禁用农药
     */
    @PreAuthorize("@ss.hasPermi('system:medicine:remove')")
    @Log(title = "禁用农药", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(disableMedicineService.deleteDisableMedicineByIds(ids));
    }
}
